package com.itheima.health.service.impl;

import com.itheima.health.common.MessageConst;
import com.itheima.health.dao.OrderDao;
import com.itheima.health.dao.OrderSettingDao;
import com.itheima.health.exception.BusinessRuntimeException;
import com.itheima.health.pojo.Order;
import com.itheima.health.pojo.OrderSetting;
import com.itheima.health.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 预约ServiceImpl
 */
@Service
@Slf4j
public class OrderServiceImpl implements OrderService {
    @Autowired
    private OrderSettingDao orderSettingDao;
    @Autowired
    private OrderDao orderDao;

    /**
     * 根据会员id,预约日期，套餐id查询预约信息
     * @param memberId
     * @param orderDate
     * @param setMealId
     * @return
     */
    @Override
    public Order getOneByCondition(Integer memberId, Date orderDate, Integer setMealId) {
       Order order= orderDao.selectOneByCondition(memberId,orderDate,setMealId);
        return order;
    }

    /**
     *  新增预约
     * @param order
     */
    @Override
    public void save(Order order) {
        orderDao.insert(order);
    }

    @Override
    public Order getOrderById(Integer id) {
        Order order =orderDao.selectOneById(id);
        return order;
    }

    /**
     * 查询今日预约数
     * @param today
     * @return
     */
    @Override
    public Integer getCountToday(String today) {
        return orderDao.selectCountToday(today,null);
    }

    @Override
    public Integer getCountWeek(String week) {
        return orderDao.selectCountWeek(week,null);
    }

    @Override
    public Integer getCountMonth(String month) {
        return orderDao.selectCountWeek(month,null);
    }

    @Override
    public Integer getCountTodayVisits(String today) {
        return orderDao.selectCountToday(today,Order.ORDERSTATUS_YES);
    }

    @Override
    public Integer getCountWeekVisits(String week) {
        return orderDao.selectCountWeek(week,Order.ORDERSTATUS_YES);
    }

    @Override
    public Integer getCountMonthVisits(String month) {
        return orderDao.selectCountWeek(month,Order.ORDERSTATUS_YES);
    }

    @Override
    public List<Map<String, Object>> hoteSetmeal() {
        return orderDao.getListHoteSetmeal();
    }

    @Override
    public Integer getCount() {
        return orderDao.getCount();
    }
}
